// Rcursive Sort No Loops
// Date 01:20 26/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
using namespace std;
using std::cout;
using std::endl;

void Display(int *d, int size){
	int *ptr = d;
	int i = 0;
	while (i < size){
		//Print out the item using the address of the array contents
		cout << *ptr << " ";
		*ptr++;
		i++;
	}
	cout << endl;
}

void MySort(int *d, int start, int end){
	//Rcursive Sort No Loops
	if (start >= end - 1){return;}

	if (d[start] > d[start + 1]){
		//Swap elements
		swap(d[start + 1], d[start]);
		//Call sort procedure
		MySort(d, start + 1, end);
		MySort(d, start, end-1);
	}
	else{
		return;
	}
}

int main(int argc, char *argv[]){
	int nums[] = { 60, 30, 50, 20, 10, 40,8,0,7,5,6,2,1,3 };

	int len = sizeof(nums) / sizeof(int);

	cout << "Original : ";
	Display(nums, len);
	//Sort numbers
	cout << endl;
	MySort(nums, 0, len);
	cout << "Rcursive Sort : ";
	Display(nums, len);

	system("pause");
	return 0;
}